package com.scwatch.core.domain;

import com.google.common.base.Objects;
import com.scwatch.ext.domain.Vote;

import javax.persistence.*;
import java.io.Serializable;

/**
 * Created by rh005 on 2017/7/26.
 */
@Entity
@Table(name = "cms_info_vote")
@IdClass(InfoVote.InfoVoteId.class)
public class InfoVote implements java.io.Serializable{
    private static final long serialVersionUID = 1L;

    @Id
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "f_info_id", nullable = false)
    private Info info;

    @Id
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "f_vote_id", nullable = false)
    private Vote vote;

    public InfoVote() {
    }

    public InfoVote(Info info, Vote vote) {
        this.info = info;
        this.vote = vote;
    }

    public Info getInfo() {
        return info;
    }

    public void setInfo(Info info) {
        this.info = info;
    }

    public Vote getVote() {
        return vote;
    }

    public void setVote(Vote vote) {
        this.vote = vote;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (!(o instanceof InfoVote)) {
            return false;
        }
        InfoVote that = (InfoVote) o;
        return Objects.equal(info, that.info) && Objects.equal(vote, that.vote);
    }

    @Override
    public int hashCode() {
        return Objects.hashCode(info, vote);
    }

    public static class InfoVoteId implements Serializable {
        private static final long serialVersionUID = 1L;

        Integer info;
        Integer vote;

        public InfoVoteId() {
        }

        public InfoVoteId(Integer infoId, Integer voteId) {
            this.info = infoId;
            this.vote = voteId;
        }

        @Override
        public boolean equals(Object o) {
            if (this == o) {
                return true;
            }
            if (!(o instanceof InfoVote.InfoVoteId)) {
                return false;
            }
            InfoVote.InfoVoteId that = (InfoVote.InfoVoteId) o;
            return Objects.equal(info, that.info) && Objects.equal(vote, that.vote);
        }

        @Override
        public int hashCode() {
            return Objects.hashCode(info, vote);
        }
    }
}
